package com.qyb;

/**
 * <strong>实现功能:</strong>
 * <p></p>
 *
 * @author 秦有宝(qinyoubao)
 * @version 1.0.0  2019/11/15 15:41
 */
public class Recurse {
    public static void main(String[] args) {
        //System.out.println(fib(100));   //5050

        int[][]  rr = init();
        print(rr);

        System.out.println("--------------------------");

        run(rr,1,1,6,6);
        print(rr);

    }


    public static boolean run(int[][] rr, int starti, int startj, int endi, int endj){
        if(starti<0 || starti>=rr.length){
            return false;
        }
        if(startj<0 || startj>=rr[0].length){
            return false;
        }
        if(rr[starti][startj] != 0){
            return false;
        }

        rr[starti][startj] = 2;

        if(starti == endi && startj == endj){
            return true;
        }

        if(run(rr, starti+1, startj, endi, endj)){  //向右
            return true;
        }else if(run(rr, starti, startj+1, endi, endj)){  //向下
            return true;
        }else if(run(rr, starti - 1, startj, endi, endj)){  //向左
            return true;
        }else if(run(rr, starti, startj-1, endi, endj)){  //向上
            return true;
        }
        rr[starti][startj] = 3;
        return false;

    }


    public static int fib(int num){
        if(num == 1){
            return num;
        }
        return fib(num -1) + num;
    }

    //mi
    public static int[][] init(){
        int[][]  rr = new int[8][8];
        rr[0][0] = 1;
        rr[1][0] = 1;
        rr[2][0] = 1;
        rr[3][0] = 1;
        rr[4][0] = 1;
        rr[5][0] = 1;
        rr[6][0] = 1;
        rr[7][0] = 1;

        rr[0][1] = 1;
        rr[0][2] = 1;
        rr[0][3] = 1;
        rr[0][4] = 1;
        rr[0][5] = 1;
        rr[0][6] = 1;
        rr[0][7] = 1;

        rr[7][1] = 1;
        rr[7][2] = 1;
        rr[7][3] = 1;
        rr[7][4] = 1;
        rr[7][5] = 1;
        rr[7][6] = 1;
        rr[7][7] = 1;

        rr[1][7] = 1;
        rr[2][7] = 1;
        rr[3][7] = 1;
        rr[4][7] = 1;
        rr[5][7] = 1;
        rr[6][7] = 1;

        rr[1][4] = 1;
        rr[2][4] = 1;
        rr[5][4] = 1;
        return rr;
    }
    
    
    public static void print(int[][] rr){
        for (int i = 0; i < rr.length; i++) {
            for (int j = 0; j < rr[i].length; j++) {
                System.out.printf("%d\t",rr[j][i]);
            }
            System.out.println();
        }
    }

}
